package com.zhkj.txg.module.mine.vm


import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.zhkj.lib.base.BaseViewModel
import com.zhkj.lib.http.HttpResponse
import com.zhkj.lib.http.ViewModelSubscribeListener
import com.zhkj.lib.utils.AccountManager
import com.zhkj.txg.module.mine.entity.RefundListResponse
import com.zhkj.txg.module.mine.model.MineManager

class AfterSaleViewModel(application: Application) : BaseViewModel(application) {
    private val manager = MineManager()

    val refundListLiveData = MutableLiveData<HttpResponse<RefundListResponse>>()

    private val numb = 20
    var page = 1
        private set

    fun list(restart: Boolean = false) {
        val listener = object : ViewModelSubscribeListener<RefundListResponse>(refundListLiveData) {
            override fun onSuccess(resp: RefundListResponse) {
                resp.hasMore = resp.data.size >= numb
                resp.loadMore = page > 1
                super.onSuccess(resp)
                page += 1
            }
        }
        if (restart) page = 1
        val refundList = manager.refundList(AccountManager.getToken(), page, numb, listener)
        dispose.add(refundList)
    }
}